﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PEMain.aspx.cs" Inherits="JTBox.Forms.PE.PEMain" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
	<meta charset="UTF-8">
	<title></title>
    <link href="../../css/default.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" href="../../js/jquery-easyui-1.3.6/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="../../js/jquery-easyui-1.3.6/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="../../js/jquery-easyui-1.3.6/demo/demo.css" />
    <script type="text/javascript" src="../../js/jquery-easyui-1.3.6/jquery.min.js"></script>
    <script type="text/javascript" src="../../js/jquery-easyui-1.3.6/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../../js/swfupload/swfupload.js"></script>
    <script type="text/javascript" src="handlers.js"></script>
    <script type="text/javascript">
        var swfu;
        var i_btn;
        window.onload = function () {
            swfu = new SWFUpload({
                // Backend Settings
                upload_url: "upload.aspx",
                post_params: {
                    "ASPSESSID": "<%=Session.SessionID %>"
                },

                // File Upload Settings
                file_size_limit: "1024 MB",
                file_types: "*.*",  //"*.jpg",
                file_types_description: "ALL Files",    //"JPG Images",
                file_upload_limit: "0",    // Zero means unlimited

                // Event Handler Settings - these functions as defined in Handlers.js
                //  The handlers are not part of SWFUpload but are part of my website and control how
                //  my website reacts to the SWFUpload events.
                file_queue_error_handler: fileQueueError,
                file_dialog_complete_handler: fileDialogComplete,
                upload_progress_handler: uploadProgress,
                upload_error_handler: uploadError,
                upload_success_handler: uploadSuccess,
                upload_complete_handler: uploadComplete,

                // Button settings
                button_image_url: "../../images/XPButtonNoText_160x22.png",
                button_placeholder_id: "spanButtonPlaceholder",    //"spanButtonPlaceholder",
                button_width: 160,
                button_height: 22,
                button_text: '<span class="button">选择文件 <span class="buttonSmall">（ 小于 1G ）</span></span>',
                button_text_style: '.button { font-family: Helvetica, Arial, sans-serif; font-size: 14pt; } .buttonSmall { font-size: 10pt; }',
                button_text_top_padding: 1,
                button_text_left_padding: 5,

                // Flash Settings
                flash_url: "../../js/swfupload/swfupload.swf", // Relative to this file

                custom_settings: {
                    upload_target: "divFileProgressContainer"
                },

                // Debug Settings
                debug: false
            });
        }

        $(function () {
            $('#w').window('close');
            $('#w2').window('close');
            
			$('#tt_pe').treegrid({
				//title:'TreeGrid',
				iconCls:'icon-save',
				//width:700,
				//height:350,
				nowrap: false,
				rownumbers: true,
				animate:true,
				collapsible:true,
				url:'PEMain.aspx',
				idField:'name',
				treeField: 'name',
				//loadFilter: pagerFilter,
				//pagination: true,
				pageSize: 2,
				pageList: [1,2,5,10],
				frozenColumns:[[
	                {title:'名称',field:'name',width:250,
		                formatter:function(value){
		                	return '<span style="color:red">'+value+'</span>';
		                }
	                }
				]],
				columns:[[
					//{field:'name',title:'名称',width:150},
					{field:'val',title:'数值',width:400,rowspan:2},
					{field:'oth',title:'说明',width:250,rowspan:2}
				]],
				onBeforeLoad:function(row,param){
					if (row){
						$(this).treegrid('options').url = 'treegrid_subdata.json';
					} else {
						$(this).treegrid('options').url = 'treegrid_data.json';
					}
				},
				onContextMenu: function(e,row){
					e.preventDefault();
					$(this).treegrid('unselectAll');
					$(this).treegrid('select', row.code);
					$('#mm').menu('show', {
						left: e.pageX,
						top: e.pageY
					});
				}
			});
            /*
			$('#tt_pe').treegrid("getPager").pagination({
			    total: 100,
			    pageList: [2, 5, 10],
			    onSelectPage: function (pageNumber, pageSize) {
			        $(this).pagination('loading');
			        //
			        alert('a');
			        $(this).pagination('loaded');
			    }
			});
            */
        })

        function pagerFilter(){
            $('#tt_pe').treegrid("getPager").pagination({
                onSelectPage: function (pageNumber, pageSize) {
                    $(this).pagination('loading');
                    var sUrl = "PEMain.aspx?cmd=read&typ=" + i_btn + "&id_temp=" + Math.random();
                    $('#tt_pe').treegrid({ url: sUrl });
                    $('#tt_pe').treegrid('refresh');
                    $(this).pagination('loaded');
                }
            });
        }


        function btnclick(i_btn) {
            this.i_btn = i_btn;
            $.get('../../Default.aspx', { cmd: 'islogin', id_temp: Math.random() }, function (data) {
                var sJson = eval('(' + data + ')');
                if (sJson['sta'] != 1) {
                    alert("请登录");
                    window.parent.btnclick(1);
                    return;
                } else {
                    switch (i_btn) {
                        case 1:
                            $('#w').window('open');

                            break;
                        case 2:
                            $('#w2').window('open');
                            $('#tt').datagrid({
                                url: 'PEMain.aspx?cmd=getfilelist&id_temp=' + Math.random(),
                                //title: 'DataGrid - ContextMenu',
                                //width: 500,
                                height: 'auto',
                                fitColumns: true,
                                singleSelect: true,
                                columns: [[
                                    { field: 'f_id', title: 'ID', width: 20 },
                                    { field: 'filename', title: '文件名', width: 200 },
                                    { field: 'size', title: '大小', width: 40, align: 'right' },
                                    { field: 'dat_s', title: '上传日期', width: 120, align: 'right' }
                                    //{ field: 'md5', title: 'md5', width: 50 },
                                    //{ field: 'sha1', title: 'sha1', width: 60, align: 'center' }
                                ]],
                                onHeaderContextMenu: function (e, field) {
                                    e.preventDefault();
                                    if (!$('#tmenu').length) {
                                        createColumnMenu();
                                    }
                                    $('#tmenu').menu('show', {
                                        left: e.pageX,
                                        top: e.pageY
                                    });
                                }
                            });                 
                                  
                            break;
                            case 3:
                                var selected = $('#tt').datagrid('getSelected');
                                if (selected) {
                                    var f_id = selected.f_id;
                                    var filename = selected.filename;
                                    var dat_s = selected.dat_s;
                                    $.get('PEMain.aspx',{cmd:'openpe', f_id:f_id, typ:0, id_temp:Math.random()}, function(data){
                                        var Json = eval('(' + data + ')');
                                        $('#tt_pe').treegrid('loadData', Json);
                                    });
                                    
                                }
                                $('#w2').window('close');
                            break;
                            case 10:
                            case 11:
                            case 12:
                            case 13:
                            case 14:
                            case 15:
                            case 16:
                                /*var sUrl = "PEMain.aspx?cmd=read&typ=" + i_btn + "&id_temp=" + Math.random();
                                $('#tt_pe').treegrid({ url: sUrl });
                                $('#tt_pe').treegrid('refresh');
                                */
                                
                                $.get('PEMain.aspx', {cmd:'read', typ:i_btn, id_temp:Math.random()}, function(data){
                                    try
                                    {
                                        var Json = eval('(' + data + ')');
                                        $('#tt_pe').treegrid('loadData', Json);
                                    }
                                    catch(e)
                                    {
                                        alert(e);
                                    }
                                });
                                
                            break;
                        default:
                    }                
                }
            })        

        }
    </script>    
</head>
<body  class="easyui-layout">
    <div data-options="region:'north',border:false" style="height:30px;background:#E0ECFF;padding:2px">
        <!--<div class="easyui-panel" style="padding:3px;">-->
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-upload',plain:true" onclick="btnclick(1);">上传</a>
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-open',plain:true" onclick="btnclick(2);">打开</a>
        <!--</div>-->
    </div>
	<div data-options="region:'west',split:true,title:''" style="width:150px;padding:10px;">
    			<p><a href="#"  data-options="iconCls:'icon-add'" target="center" onclick="btnclick(10)">DOS头</a></p>
				<p><a href="#"  data-options="iconCls:'icon-add'" target="center" onclick="btnclick(11)">PE头</a></p>
				<p><a href="#"  data-options="iconCls:'icon-add'" target="center" onclick="btnclick(12)">数据目录表</a></p>
				<p><a href="#"  data-options="iconCls:'icon-add'" target="center" onclick="btnclick(13)">区块表</a></p>
				<p><a href="#"  data-options="iconCls:'icon-add'" target="center" onclick="btnclick(14)">输入表</a></p>
				<p><a href="#"  data-options="iconCls:'icon-add'" target="center" onclick="btnclick(15)">输出表</a></p>
				<p><a href="#"  data-options="iconCls:'icon-add'" target="center" onclick="btnclick(16)">资源</a></p>
    </div>
	<!--<div data-options="region:'east',split:true,collapsed:true,title:'East'" style="width:100px;padding:10px;">east region</div>
	<div data-options="region:'south',border:false" style="height:50px;background:#A9FACD;padding:10px;">south region</div>-->
	<div data-options="region:'center',title:''">
    	<table id="tt_pe"></table>

        <div id="mm" class="easyui-menu" style="width:120px;">
            <div onclick="append()">Append</div>
            <div onclick="remove()">Remove</div>
        </div>
    </div>
    

    <div id="w" class="easyui-window" data-options="title:'上传文件',iconCls:'icon-save'" style="width: 400px; height: 200px; padding: 5px;">
        <div class="easyui-layout" data-options="fit:true">
            <div data-options="region:'center',border:false" style="padding: 10px; background: #fff; border: 1px solid #ccc;">
                <div id="swfu_container">
                    <div>
                        <span id="spanButtonPlaceholder"></span>
                    </div>
                    <div id="divFileProgressContainer" style="height: 75px;">
                    </div>
                    <div id="thumbnails">
                    </div>
                </div>
            </div>
            <div data-options="region:'south',border:false" style="text-align: right; padding: 5px 0;">
                <a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="$('#w').window('close')">关闭</a>
            </div>
        </div>
    </div>
    <div id="w2" class="easyui-window" data-options="title:'选择文件',iconCls:'icon-save'" style="width: 550px; height: 300px; padding: 5px;">
        <div class="easyui-layout" data-options="fit:true">
            <div data-options="region:'center',border:false" style="padding: 0px; background: #fff; border: 1px solid #ccc;">
                <table id="tt"></table>
            </div>
            <div data-options="region:'south',border:false" style="text-align: right; padding: 5px 0;">
                <a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="btnclick(3)">确定</a>
                <a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="$('#w2').window('close')">关闭</a>
            </div>
        </div>
    </div>
</body>
</html>
